<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>appscript | 8. Real vs. Generic References</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all"><!--@import url(full.css);--></style>

</head>
<body>

<h1>8. Real vs. Generic References</h1>

<!-- top navigation -->
<div class="navbar">
	<a href="07_applicationobjects.html">Previous</a> | <a href="index.html">Up</a> | <a href="09_referenceforms.html">Next</a>
	
</div>

<!-- content -->
<div id="content">

<h2>Real vs. generic references</h2>

<p>References may be either 'real' or 'generic'. A real reference includes an AEAddressDesc for a specific application, while a generic reference doesn't. Generic references provide a convenient shortcut for writing literal references without having to specify a particular application object each time.</p>


<p>A generic reference begins with a glue-defined App, Con or Its macro, e.g.:</p>

<pre><code>[[TEApp documents] text];
[[TECon word] at: 3];
[[TEIts name] startsWith: @"d"];</code></pre>

<p>Generic references can only be used within real references, either as selectors:</p>

<pre><code>[[[finder home] folders] byTest: <em>[[FNIts name] startsWith: @"d"]</em>]

[[[texEditPlus windows] at: 1] text] byRange: <em>[[TEPCon words] at: 2]</em>
                                          to: <em>[[TEPCon words] at: -2]</em>]</code></pre>

<p>or as command parameters:</p>

<pre><code>[[[[textedit make]
              new: [TEConstant word] 
               at: <em>[[[[TEApp documents] at: 1] words] end]</em>]
         withData: @"Hello"];

[[[finder desktop]
        duplicate] to: <em>[[[FNApp home] folders] byName: @"Desktop Copy"]</em>];</code></pre>


<p>A real reference begins with a reference to an Application object that identifies the application to which commands will be sent, e.g.:</p>

<pre><code>#import "TEGlue.h"

TEApplication *textedit = [[TEApplication alloc] initWithName: @"TextEdit"];

TEReference *realRef = [[textedit documents] text];</code></pre>

<p>Only Application objects and references that have Application objects as their roots can be used to send events. For example, these work:</p>

<pre><code>[[[textedit set: [[TEApp documents] text]] to: @"Hello World!"] send];

[[[realRef set] to: @"Hello World!"] send];</code></pre>


<p>but this doesn't:</p>

<pre><code>[[[[[TEApp documents] text] set] to: @"Hello World!"] send];</code></pre>


<!--TO DO
<h2>Comparing and hashing references</h2>

<p>Application references can be compared for equality and are hashable (so can be used as dictionary keys). For two real references to be considered equal, both must have the same application path or url and reference structure. Examples:</p>

<pre><code>puts app('TextEdit').documents[1] == \
    app.by_id('com.apple.textedit').documents[1].get
# Result: true; both references evaluate to the same
#     application path and reference

puts app('Finder').home == app('Finder').home.get
# Result: false; app('Finder').home.get returns a
#     different reference to the same location</code></pre>

<p>For two generic references to be equal, both must have the same reference structure. Note that comparing generic references to real references will always return a false result.</p>
-->


</div>

<!-- bottom navigation -->
<div class="navbar">
	<a href="07_applicationobjects.html">Previous</a> | <a href="index.html">Up</a> | <a href="09_referenceforms.html">Next</a>
	
</div>

<!--footer-->
<p class="footer">&copy; 2007 HAS</p>
</body>
</html>